﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		Post.Validation.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 //   File:            Post.Validation.cs
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using Topics.Radical.Validation;

namespace Dexter.Domain.Model {
	public partial class Post {
		public virtual void ValidateForPublish ( ) {
			Ensure.That ( Id )
				.Named ( "Id" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.Is ( 0 )
				.WithMessage ( "Invalid post key." );

			Ensure.That ( Title )
				.Named ( "Title" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotEmpty ( )
				.WithMessage ( "Invalid post title." );

			Ensure.That ( Username )
				.Named ( "Username" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotEmpty ( )
				.WithMessage ( "Invalid post Username." );

			Ensure.That ( Slug )
				.Named ( "Slug" )
				.WithPreview ( ( v, e ) => Logger.Warn ( v.GetFullErrorMessage ( ), e ) )
				.IsNotEmpty ( )
				.WithMessage ( "Invalid post slug." );

			Ensure.That ( this.Categories )
				.Named ( "Username" )
				.WithPreview ( ( v, e ) => Logger.Warn ( v.GetFullErrorMessage ( ), e ) )
				.IsNotNull (  )
				.WithMessage ( "Invalid post category." );

			Ensure.That ( this.Categories.Count )
				.Named ( "Username" )
				.WithPreview ( ( v, e ) => Logger.Warn ( v.GetFullErrorMessage ( ), e ) )
				.IsGreaterThen ( 0 )
				.WithMessage ( "Invalid post category." );
		}

		public virtual void ValidateForUpdate()
		{
			Ensure.That(Id)
				.Named("Id")
				.WithPreview((v, e) => Logger.Warn(v.GetFullErrorMessage(), e))
				.IsGreaterThen(0)
				.WithMessage("Invalid post key.");

			Ensure.That(Title)
				.Named("Title")
				.WithPreview((v, e) => Logger.Warn(v.GetFullErrorMessage(), e))
				.IsNotEmpty()
				.WithMessage("Invalid post title.");

			Ensure.That(Username)
				.Named("Username")
				.WithPreview((v, e) => Logger.Warn(v.GetFullErrorMessage(), e))
				.IsNotEmpty()
				.WithMessage("Invalid post Username.");
		}
	}
}